// +----------------------------------------------------------------------
// | CmsWing [ 美业管理系统 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 psi All rights reserved.
// +----------------------------------------------------------------------
// | Author: huang <2374266244@qq.com>
// +----------------------------------------------------------------------
'use strict';
import Base from './base.js';

export default class extends Base {
  /**
   * index action
   * @return {Promise} []
   */
	async indexAction(){
		this.meta_title = 'app职位管理';
		return this.display();
	}
	
	async addpositionAction(){
		if(this.isPost){
			let res = await this.model('app_position').add(this.post());
			return res?this.success({info:"添加成功！"}):this.fail('添加失败！');
		}
		return this.display();	
	}
	
	async positionlistAction(){
		let plist = await this.model('app_position').select();
		let relist = {
            "draw": '',
            "data": plist,
            "breadcrumb":''
        }
		return this.json(relist);
	}
	
	async editpositionAction(){
		if(this.isPost){
			let data = this.post();
			data['s_num'] = data['s_num']?data['s_num']:0;
			let res = await this.model('app_position').where({id:this.post('id')}).update(data);
			return res?this.success({info:"编辑成功！"}):this.fail('编辑失败！');
		}
		let id = this.get('id');
		let pinfo = await this.model('app_position').where({id:id}).find();
		this.assign('pinfo',pinfo);
		return this.display();
	}
	
	async deletepositionAction(){
		let id = this.post('id');
		let res = await this.model('app_position').where({id:id}).delete();
		return res?this.success({info:"删除成功！"}):this.fail('删除失败！');
	}
}